package com.common.core.base.dos;

import com.alibaba.fastjson2.annotation.JSONField;

import java.io.Serializable;
import java.time.LocalDateTime;



public class BaseDO<T extends BaseDO<T>> implements Serializable {
    private static final long serialVersionUID = 1L;

    private int status;

    private String createBy;

    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;

    private String updateBy;

    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getCreateBy() {
        return createBy;
    }

    public void setCreateBy(String createBy) {
        this.createBy = createBy;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public String getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(String updateBy) {
        this.updateBy = updateBy;
    }

    public LocalDateTime getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }

    public T initBase(Long userId) {
        this.setCreateBy(userId.toString());
        this.setUpdateBy(userId.toString());
        this.setCreateTime(LocalDateTime.now());
        this.setUpdateTime(LocalDateTime.now());
        this.setStatus(0);
        return (T) this;
    }


    public T updateBase(Long userId) {
        this.setUpdateBy(userId.toString());
        this.setUpdateTime(LocalDateTime.now());
        return (T) this;
    }

    public T delBase(Long userId) {
        this.setStatus(1);
        this.setUpdateBy(userId.toString());
        this.setUpdateTime(LocalDateTime.now());
        return (T) this;
    }

    public T createBase(Long userId) {
        this.setCreateBy(userId.toString());
        this.setCreateTime(LocalDateTime.now());
        return (T) this;
    }

    public T createBase() {
        this.setCreateTime(LocalDateTime.now());
        return (T) this;
    }

    public T updateBase() {
        this.setUpdateTime(LocalDateTime.now());
        return (T) this;
    }
}
